package com.hontech.bv.ui

import android.widget.ArrayAdapter
import com.hontech.bv.R
import com.hontech.bv.app.AppContext
import com.hontech.bv.ui.window.showProg


fun spinnerAdapter(strings: Array<String>): ArrayAdapter<String> {
    val adapter = ArrayAdapter(AppContext, R.layout.item_spinner, strings)
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
    return adapter
}

suspend fun wrapDialog(title: String, msg: String, ctrl: suspend () -> Unit) {

    val dialog = showProg(title, msg)
    try {
        val cur = System.currentTimeMillis()
        ctrl()
        val end = System.currentTimeMillis()
        dialog.success("$msg 成功 耗时：${(end - cur) / 1000}秒")
    } catch (e: Exception) {
        e.printStackTrace()
        dialog.error(e)
    }
}

